<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <script src='/static/jquery/jquery.min.js'></script>
    <script src='/static/jquery/jquery.cookie.js'></script>
    <script src='/static/js/utools.js?version={$version}'></script>
    <script src='/static/layui/layui.js'></script>
    <link rel="styleSheet" href="/static/css/index.css?version={$version}">
    <link rel="styleSheet" href="/static/layui/css/layui.css">
    <title>用户编辑</title>
</head>
<body style="overflow-x: hidden">
<form class="layui-form layui-form-pane" style="padding: 15px" action="" lay-filter="user">
    <div class="layui-form-item">
        <label class="layui-form-label">账号</label>
        <div class="layui-input-block">
            <input type="text" name="mobile" lay-verify="required" lay-reqtext="请填写手机号或邮箱" placeholder="手机号/邮箱" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <label class="layui-form-label">uid</label>
        <div class="layui-input-block">
            <input type="text" name="uid" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <select name="status" lay-filter="status">
                <option value="1">正常</option>
                <option value="2">封禁</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户空间</label>
        <div class="layui-input-block" style="display: flex;align-items: center;gap: 10px">
            <input type="number" name="total_store" placeholder="请输入新用户注册初始空间 单位：KB"
                   class="layui-input" min="0" step="1000" lay-affix="number">
            <div style="width: 80px" id="format">0KB</div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">角色</label>
        <div class="layui-input-block">
            <select name="manager" lay-filter="status">
                <option value="0">普通用户</option>
                <option value="1">管理员</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <button type="submit" class="layui-btn layui-btn-fluid layui-bg-orange" lay-submit lay-filter="demo1">立即提交</button>
    </div>
</form>
<script>
    layui.use(['form', 'laydate', 'util'], function(){
        const form = layui.form;
        form.val("user",JSON.parse('{$user_get | raw}'))
        // 提交事件
        form.on('submit(demo1)', function(data){
            const field = data.field; // 获取表单字段值
            $.ajax({
                url:'/index/admin/user_get',
                type:'post',
                data:field,
                success:res=>{
                    if(res.code===1){
                        const index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe 层的索引
                        parent.layer.close(index); // 再执行关闭
                    }
                }
            })
            // 此处可执行 Ajax 等操作
            // …
            return false; // 阻止默认 form 跳转
        });

        $('[name="total_store"]').on("input", function (e) {
            renderFormat()
        })
        renderFormat()
        function renderFormat(){
            $("#format").html(formatBytes($('[name="total_store"]').val()))
        }
    });
</script>

</body>
</html>